/*
* 对 type 进一步的封装，只需要调用一个函数，返回对应的 type 即可
* */

import {ADD, SUB, HIDE_AD} from "./actionTypes";

const add = function (goodsId) {
    return {
        type: ADD,
        goodsId
    }
}

const asynCAdd = function (goodsId) {
    return function (dispatch) {

        /*做异步操作，操作完成后在使用 dispatcha派发修改仓库数据*/
        setTimeout(() => {
            dispatch(add(goodsId))
        }, 2000)


    }
}


const sub = function (goodsId) {
    return {
        type: SUB,
        goodsId
    }
}


const hideAd = function (id) {
    return {
        type: HIDE_AD,
        id,
    }
}


export {
    add,
    sub,
    hideAd,
    asynCAdd,
}
